package com.baselibrary.utils;

import static com.baselibrary.BaseConstant.USER_ID;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;

import com.baselibrary.Constants;
import com.baselibrary.UserInfo;
import com.baselibrary.bean.DictionaryData;
import com.baselibrary.bean.WineryInfoSaveBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;

public class SpUtils {
    public static final String GUIDE_VERSION = "_VERSION_1";//如有又tm更新同一处的引导，这里_1改成_2即可
    public static String SP_DATA = "sp_data";
    public static String LOAD_USERINFO = "load_userinfo";
    public static String LOAD_DICTIONARY = "load_dictionary";
    public static String LOAD_DOCUMENT = "load_Document";//公文系统roken
    public static String LOAD_MANMINCONFIGURE = "Load_ManMinConfigure";//我  界面动态布局数据缓存
    public static String LOAD_ADVERT = "LOAD_ADVERT";//广告数据
    public static String USER_TOKEN = "USER_TOKEN";//用户token
    public static String LOAD_SCAN_CODE = "LOAD_SCAN_CODE";//扫码是否显示 新 图标
    public static String LOAD_FANS_GUIDE_MINE = "LOAD_FANS_IS_SCANCODE";//是否扫描了粉丝大礼包的二维码
    public static String LOAD_FANS_GUIDE_MINE_LOGIN = "LOAD_FANS_IS_SCANCODE_LOGIN";//粉丝大礼包扫码 是否登录，未登录登陆完成后显示弹窗
    public static String LOAD_FANS_GUIDE_MINE_CODE = "LOAD_FANS_IS_SCANCODE_CODE";//粉丝大礼包扫码 是否登录，未登录登陆完成后显示弹窗 二维码数据
    public static String LOAD_FANS_GUIDE_HOME = "LOAD_FANS_GUIDE_HOME";//首页是否显示指引
    public static String LOAD_FANS_GUIDE_BADGE = "LOAD_FANS_GUIDE_BADGE" + GUIDE_VERSION;//【专属徽章】是否显示指引
    public static String LOAD_HEADER_GUIDE_BADGE = "LOAD_HEADER_GUIDE_BADGE" + GUIDE_VERSION;//头像是否显示指引
    public static String LOAD_MINE_MEMBER_MAKER = "LOAD_MINE_MEMBER_MAKER";//加载【我的界面】会员中心的角标是否点击过
    public static String LOAD_ACTIVE_POP_BEAN = "LOAD_ACTIVE_POP_BEAN";//首页banner弹窗 活动列表的json
    public static String LOAD_ACTIVE_IMG_URL_BEAN = "LOAD_ACTIVE_IMG_URL_BEAN";//首页活动弹窗 配置 图片url 的bean
    public static String LOAD_TODAY_HAS_POP = "LOAD_TODAY_HAS_POP";//任务今天是否弹过窗
    public static String LOAD_IS_SHOW_ZERO_BUY_BOTTOM_TIP_SHOW_TIME = "LOAD_IS_SHOW_ZERO_BUY_BOTTOM_TIP_SHOW_TIME";// 显示 0元购 底部提示的时间
    public static String LOAD_IS_SHOW_ZERO_BUY_BOTTOM_TIP_CNT = "LOAD_IS_SHOW_ZERO_BUY_BOTTOM_TIP_CNT";//0元购底部提示点击关闭次数
    public static String LOAD_PERMISSIONS = "LOAD_PERMISSIONS";//是否授权
    public static String LOAD_ZEROBUY_CONFIGBEAN = "LOAD_ZEROBUY_CONFIGBEAN";//0元购相关配置
    public static String LOAD_ZEROBUY_CLOSE_POP = "LOAD_ZEROBUY_CLOSE_POP";//点击关闭0元购首页弹窗
    public static String LOAD_IS_SHOW_ZERO_BUY_VISITOR_COUNT_TIME = "LOAD_IS_SHOW_ZERO_BUY_VISITOR_COUNT_TIME";//访客数 统计
    public static String LOAD_IS_SHOW_ZERO_BUY_ACTIVITY_STATEMENT = "LOAD_IS_SHOW_ZERO_BUY_ACTIVITY_STATEMENT";//0元购活动声明弹窗是否点击同意
    public static String LOAD_MATERIAL_LIBRARY_DOCUMENT_DOWNLOAD_PERMISSION = "LOAD_MATERIAL_LIBRARY_DOCUMENT_DOWNLOAD_PERMISSION";//素材库文档下载权限
    public static String LOAD_OPENINSTALL_JUMP_URL = "LOAD_OPENINSTALL_JUMP_URL";//openinstall 传过来的参数
    public static String LOAD_OPENINSTALL_JUMP_URL_IS_FRIST = "LOAD_OPENINSTALL_JUMP_URL_IS_FRIST";//是否携参安装（首次）
    public static String LOAD_OPENINSTALL_SAVE_CHANNEID = "LOAD_OPENINSTALL_SAVE_CHANNEID";//存储渠道id

    public static String LOAD_DEVICE_TOKEN = "LOAD_DEVICE_TOKEN";//设备token
    public static String LOAD_ONEKEY_LOGIN_IS_ALLOW = "LOAD_ONEKEY_LOGIN_IS_ALLOW";//一键登录-是否允许协议
    public static String LOAD_MQ_LAST_MESSAGE = "LOAD_MQ_LAST_MESSAGE";//保存美洽发送的最后一条消息
    public static String LOAD_MQ_LAST_MESSAGE_TIME = "LOAD_MQ_LAST_MESSAGE_TIME";// 保存美洽发送的最后一条消息的时间
    public static String LOAD_IS_TOGETHER_FOLLOW = "LOAD_IS_TOGETHER_FOLLOW";//是否相互关注
    public static String LOAD_DYNAMIC_IS_DRAG = "LOAD_DYNAMIC_IS_DRAG";//发布界面【长按拖动调整顺序】
    public static String LOAD_PAGE_POS_CHAT = "LOAD_PAGE_POS_CHAT";//发起位置 消息列表，好友列表、社区用户主页
    public static String LOAD_LETTER_SHOW = "LOAD_LETTER_SHOW";//老王的来信，收否展示
    public static String LOAD_GUIDE_VERSION = "LOAD_GUIDE_VERSION";//引导页版本号
    public static String LOAD_WINERY_INFO_DATA = "LOAD_WINERY_INFO_DATA";//经营者中心的酒窖信息
    public static String LOAD_LAUNCH_WINERY_MANAGE_MODE = "LOAD_LAUNCH_WINERY_MANAGE_MODE";//是否进入经营者模式
    public static String LOAD_IS_FIRST_CLICK_SWITCH_WINERY_MANAGER_MODE = "LOAD_IS_FIRST_CLICK_SWITCH_WINERY_MANAGER_MODE";//是否第一次点击切换经营者模式（false：隐藏抖动提示）
    public static String LOAD_ADD_EDIT_ONLINE_WINEY_INFO = "LOAD_ADD_EDIT_ONLINE_WINEY_INFO";//编辑酒窖信息 草稿箱
    public static String LOAD_USER_AGREE_PRIVACY = "LOAD_USER_AGREE_PRIVACY";//用户是否同意隐私政策
    public static SpUtils mInstance;
    public static SharedPreferences sharedPreferences;

    public static SpUtils getInstance() {
        if (mInstance == null) {
            synchronized (SpUtils.class) {
                if (mInstance == null) {
                    mInstance = new SpUtils();
                }
            }
        }
        return mInstance;
    }

    public SpUtils() {
        sharedPreferences = ContextUtils.getCurApplication().getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
    }


    /**
     * 发布界面 可以拖拽 提示 是否显示
     */
    public void putDynamicDrag() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_DYNAMIC_IS_DRAG, true);
        editor.apply();

    }

    /**
     * 老王来信 是否显示
     */
    public void putLetterShow() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_LETTER_SHOW, true);
        editor.apply();

    }

    /**
     * 老王来信
     *
     * @return
     */
    public boolean getLetterShow() {
        return sharedPreferences.getBoolean(LOAD_LETTER_SHOW, false);
    }

    public boolean getDynamicDrag() {
        return sharedPreferences.getBoolean(LOAD_DYNAMIC_IS_DRAG, false);
    }

    public int getId() {
        return sharedPreferences.getInt(USER_ID, 0);
    }
    public void putId(int id) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt(USER_ID, id);
        editor.apply();
    }
    //存储 经营者中心 酒窖信息
    public void saveCurrentWineryInfo(@NotNull WineryInfoSaveBean bean) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_WINERY_INFO_DATA, CommonUtil.beanToJson(bean));
        editor.apply();
    }

    //获取 经营者中心 酒窖信息
    public WineryInfoSaveBean getCurrentWineryInfo() {
        WineryInfoSaveBean bean = CommonUtil.jsonToBean(sharedPreferences.getString(LOAD_WINERY_INFO_DATA, ""), WineryInfoSaveBean.class);
        if (bean != null) {
            return bean;
        } else {
            return new WineryInfoSaveBean("", "", "", "");
        }
    }
    //保存用户信息实体类
    public void putLoadUserBean(UserInfo userInfo) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        Gson gson = new Gson();
        String json = gson.toJson(userInfo);
        editor.putString(LOAD_USERINFO, json);
        editor.apply();
    }
    //保存公文系统token
    public void putLoadDocumentToken(String token) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_DOCUMENT, token);
        editor.apply();
    }

    public String getDocumentToken() {
        return sharedPreferences.getString(LOAD_DOCUMENT, "");
    }



    //获取用户信息实体类
    public int getUserId() {
        if (getIsLogin()) {
            return getLoadUserBean().getData().getId();
        } else {
            return 0;
        }
    }


    public String getUserToken() {
        return getToken();
    }

    //保存动态布局实体类实体类
    public void putManMinConfigureJson(String json) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_MANMINCONFIGURE, json);
        editor.apply();
    }

    //首页是否显示指引
    public void putGuideHome() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_FANS_GUIDE_HOME, true);
        editor.apply();
    }

    //是否扫码
    public void putIsFansCode() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_FANS_GUIDE_MINE, true);
        editor.apply();
    }

    //【粉丝ICon】 是否显示指引
    public void putGuideFansIcon() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_FANS_GUIDE_BADGE, true);
        editor.apply();
    }

    //
    public void putIsFansCodeLogin(boolean b) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_FANS_GUIDE_MINE_LOGIN, b);
        editor.apply();
    }

    //如果去登录需要储存二维码数据
    public void putFansCodeCode(String code) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_FANS_GUIDE_MINE_CODE, code);
        editor.apply();
    }

    //头像是否显示指引
    public void putGuideHeader() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_HEADER_GUIDE_BADGE, true);
        editor.apply();
    }

    /**
     * 会员中心的new样式角标被点击
     */
    public void putMineMemberMaker() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_MINE_MEMBER_MAKER, true);
        editor.apply();
    }

    /**
     *
     */
    public void putPermissions() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_PERMISSIONS, true);
        editor.apply();
    }

    public boolean getPermissions() {
        return sharedPreferences.getBoolean(LOAD_PERMISSIONS, false);
    }


    public boolean getMineMemberMaker() {
        return sharedPreferences.getBoolean(LOAD_MINE_MEMBER_MAKER, false);
    }

    public String getFansCode() {
        return sharedPreferences.getString(LOAD_FANS_GUIDE_MINE_CODE, "");
    }

    public String getToken() {
        return  "J8+UFw2BQkmf/0Apb71AQxIrVkKRunDx1Jpnh6XSapY=";
//        return sharedPreferences.getString(USER_TOKEN, "");
    }
    public void putToken(String token) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(USER_TOKEN, token);
        editor.apply();
    }

    public boolean IsFansCodeLogin() {
        return sharedPreferences.getBoolean(LOAD_FANS_GUIDE_MINE_LOGIN, false);
    }

    public boolean getGuideHome() {
        return sharedPreferences.getBoolean(LOAD_FANS_GUIDE_HOME, false);
    }


    public boolean getIsFansCode() {
        return sharedPreferences.getBoolean(LOAD_FANS_GUIDE_MINE, false);
    }


    public boolean getGuideFansIcon() {
        return sharedPreferences.getBoolean(LOAD_FANS_GUIDE_BADGE, false);
    }


    public boolean getGuideHeader() {
        return sharedPreferences.getBoolean(LOAD_HEADER_GUIDE_BADGE, false);
    }


    //保存动态布局实体类实体类
    public void putAdvertJson(String json) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_ADVERT, json);
        editor.apply();
    }

    //获取广告数据
    public String getAdvertJson() {
        return sharedPreferences.getString(LOAD_ADVERT, "");
    }

    //获取动态布局实体类实体类
    public String getManMinConfigureJson() {
        return sharedPreferences.getString(LOAD_MANMINCONFIGURE, "");
    }


    public void clearLoadUserInfoBean() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.remove(LOAD_USERINFO);
        editor.apply();
    }

    public void clearLoadDictionaryBean() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.remove(LOAD_DICTIONARY);
        editor.apply();
    }

    //清除公文系统token
    public void clearDocumentToken() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.remove(LOAD_DOCUMENT);
        editor.apply();
    }

    private static final String TAG = "SpUtils";

    /**
     * 扫码功能上的 新 图标
     *
     * @param isClickIcon 是否点击icon  true 点击了icon
     *                    isClickIcon 点击时 次数 +1并不冲突，因为点击过后就不再展示了
     */
    public void putScanCodeNewIcon(boolean isClickIcon) {
        try {
            JSONObject mJson = null;
            String jsonStr = sharedPreferences.getString(LOAD_SCAN_CODE, "");
            if (TextUtils.isEmpty(jsonStr)) {
                mJson = new JSONObject();
                mJson.put("isClickNewIcon", false);//是否点击过
                mJson.put("newIconShowCount", 1);
            } else {
                mJson = new JSONObject(jsonStr);
                int newIconShowCount = mJson.optInt("newIconShowCount");
                if (!mJson.optBoolean("isClickNewIcon")) {//本地值 为 false时候再去执行   put 操作
                    mJson.put("isClickNewIcon", isClickIcon);//是否点击过
                    mJson.put("newIconShowCount", newIconShowCount + 1);
                }
            }
            SharedPreferences.Editor editor = sharedPreferences.edit();
            Log.d(TAG, "putScanCodeNewIcon: " + mJson.toString());
            editor.putString(LOAD_SCAN_CODE, mJson.toString());
            editor.apply();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    /**
     * @return true 显示 新 图标  /   false不显示
     */
    public boolean getScanCodeNewIcon() {
        try {
            String jsonStr = sharedPreferences.getString(LOAD_SCAN_CODE, "");
            if (TextUtils.isEmpty(jsonStr)) {
                return true;
            } else {
                JSONObject mJson = new JSONObject(jsonStr);
                long newIconShowCount = mJson.optLong("newIconShowCount");
                boolean isClickNewIcon = mJson.optBoolean("isClickNewIcon");//是否点击过
                Log.d(TAG, "newIconShowCount: " + newIconShowCount);
                if (newIconShowCount > 3 || isClickNewIcon) {
                    return false;
                } else {
                    return true;
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return true;
    }

    public void putActivePopListBean(String jsonStr) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_ACTIVE_POP_BEAN, jsonStr);
        editor.apply();
    }

    public void putTodayHasPop(String todayString) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_TODAY_HAS_POP, todayString);
        editor.apply();
    }

    public String getTodayHasPop() {
        return sharedPreferences.getString(LOAD_TODAY_HAS_POP, "");
    }

    public String getActivePopListBean() {
        return sharedPreferences.getString(LOAD_ACTIVE_POP_BEAN, "");
    }

    //存储-- 显示 0元购  的时间
    public void putBottomZeroBuyTipShowTime(long time) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putLong(LOAD_IS_SHOW_ZERO_BUY_BOTTOM_TIP_SHOW_TIME, time);
        editor.apply();
    }

    public long getBottomZeroBuyTipShowTime() {
        return sharedPreferences.getLong(LOAD_IS_SHOW_ZERO_BUY_BOTTOM_TIP_SHOW_TIME, 0);
    }


    //存储-- 0元购 底部提示点击关闭次数
    public void putClickZeroBuyTipCnt(int cnt) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt(LOAD_IS_SHOW_ZERO_BUY_BOTTOM_TIP_CNT, cnt);
        editor.apply();
    }

    public int getClickZeroBuyTipCnt() {
        return sharedPreferences.getInt(LOAD_IS_SHOW_ZERO_BUY_BOTTOM_TIP_CNT, 0);
    }

    //存储- 0元购相关配置
    public void putZeroBuyConfigBean(String json) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_ZEROBUY_CONFIGBEAN, json);
        editor.apply();
    }


    //0元购规则弹窗点击同意
    public boolean getZeroBuyActivityStatement() {
        return sharedPreferences.getBoolean(LOAD_IS_SHOW_ZERO_BUY_ACTIVITY_STATEMENT, false);
    }

    //存储素材库文档下载是否允许  canDownload：false不允许  true：允许
    public void putMaterialDocumentDownPermision(boolean canDownload) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_MATERIAL_LIBRARY_DOCUMENT_DOWNLOAD_PERMISSION, canDownload);
        editor.apply();
    }

    //获取素材库文档下载是否允许
    public boolean getMaterialDocumentDownPermision() {
        return sharedPreferences.getBoolean(LOAD_MATERIAL_LIBRARY_DOCUMENT_DOWNLOAD_PERMISSION, false);
    }

    public void putClickZeroBuyClosePop(boolean isClickClose) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_ZEROBUY_CLOSE_POP, isClickClose);
        editor.apply();
    }

    public boolean getClickZeroBuyClosePop() {
        return sharedPreferences.getBoolean(LOAD_ZEROBUY_CLOSE_POP, false);
    }

    /**
     * 0元购规则弹窗点击同意
     *
     * @return
     */
    public void putZeroBuyActivityStatement() {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_IS_SHOW_ZERO_BUY_ACTIVITY_STATEMENT, true);
        editor.apply();
    }

    //存储-- 显示 0元购  的时间
    public void putZeroBuyVisitorCountTime(long time) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putLong(LOAD_IS_SHOW_ZERO_BUY_VISITOR_COUNT_TIME, time);
        editor.apply();
    }

    public long getZeroBuyVisitorCountTime() {
        return sharedPreferences.getLong(LOAD_IS_SHOW_ZERO_BUY_VISITOR_COUNT_TIME, 0);
    }

    //存储设备token
    public void putDeviceToken(String deviceToken) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_DEVICE_TOKEN, deviceToken);
        editor.apply();
    }

    //获取设备token
    public String getDeviceToken() {
        return sharedPreferences.getString(LOAD_DEVICE_TOKEN, "");
    }

    //存储-一键登录 是否允许协议
    public void putOneKeyLoginIsAllow(boolean isAllow) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_ONEKEY_LOGIN_IS_ALLOW, isAllow);
        editor.apply();
    }

    //获取-一键登录 是否允许协议
    public Boolean getOneKeyLoginIsAllow() {
        return sharedPreferences.getBoolean(LOAD_ONEKEY_LOGIN_IS_ALLOW, false);
    }

    //h5需要打开的网页url
    public void putOpenInstallJumpUrl(String bindData) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_OPENINSTALL_JUMP_URL, bindData);
        editor.apply();
    }

    public String getOpenInstallJumpUrl() {
        return sharedPreferences.getString(LOAD_OPENINSTALL_JUMP_URL, "");
    }

    //是否是 携参安装（首次）  false:首次  true  非首次
    public void putIsOpenInstallJumpUrl4Install(boolean noFirst) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_OPENINSTALL_JUMP_URL_IS_FRIST, noFirst);
        editor.apply();
    }

    public boolean getIsOpenInstallJumpUrl4Install() {
        return sharedPreferences.getBoolean(LOAD_OPENINSTALL_JUMP_URL_IS_FRIST, false);
    }

    //存储openinstall 渠道id
    public void saveChanneId(int channelId) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt(LOAD_OPENINSTALL_SAVE_CHANNEID, channelId);
        editor.apply();
    }

    public int getChanneId() {
        return sharedPreferences.getInt(LOAD_OPENINSTALL_SAVE_CHANNEID, 0);
    }

    //发起位置 消息列表，好友列表、社区用户主页
    public void savePagePos4Chat(@NotNull String pagePos) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_PAGE_POS_CHAT, pagePos);
        editor.apply();
    }

    public String getPagePos4Chat() {
        return sharedPreferences.getString(LOAD_PAGE_POS_CHAT, "");
    }

    public void saveGuideVersion(@NotNull String pagePos) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_GUIDE_VERSION, pagePos);
        editor.apply();
    }

    public String getGuideVersion() {
        return sharedPreferences.getString(LOAD_GUIDE_VERSION, "");
    }




    //是否进入经营者模式
    public void saveLaunchWineryManage(boolean isEnterManage) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_LAUNCH_WINERY_MANAGE_MODE, isEnterManage);
        editor.apply();
    }

    public boolean getLaunchWineryManage() {
        return sharedPreferences.getBoolean(LOAD_LAUNCH_WINERY_MANAGE_MODE, false);
    }


    //是否 点击过切换经营者模式（true：隐藏抖动提示）
    public void saveIsClickSwitchWineryManagerMode(boolean isClicked) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_IS_FIRST_CLICK_SWITCH_WINERY_MANAGER_MODE, isClicked);
        editor.apply();
    }

    public boolean getIsFirstClickSwitchWineryManagerMode() {
        return sharedPreferences.getBoolean(LOAD_IS_FIRST_CLICK_SWITCH_WINERY_MANAGER_MODE, false);
    }

    //存储 酒窖编辑 信息 草稿
    public void saveAddEditOnlineWineyInfo(String json) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(LOAD_ADD_EDIT_ONLINE_WINEY_INFO, json);
        editor.apply();
    }

    //获取 酒窖编辑-草稿
    public String getAddEditOnlineWineyInfoJson() {
        return sharedPreferences.getString(LOAD_ADD_EDIT_ONLINE_WINEY_INFO, "");
    }

    public void setUserAgreePrivacy(boolean agreePrivacy) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(LOAD_USER_AGREE_PRIVACY, agreePrivacy);
        editor.apply();
    }

    public boolean getUserAgreePrivacy() {
        return sharedPreferences.getBoolean(LOAD_USER_AGREE_PRIVACY, false);
    }


    public static boolean put(Context context, String key, Object value) {
        SharedPreferences preferences = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = preferences.edit();

        if (value instanceof String) {
            if (!TextUtils.isEmpty((CharSequence) value)) {
                edit.putString(key, (String) value);
            }
        } else if (value instanceof Boolean) {
            edit.putBoolean(key, (Boolean) value);

        } else if (value instanceof Float) {
            edit.putFloat(key, (Float) value);

        } else if (value instanceof Integer) {
            edit.putInt(key, (Integer) value);
        } else {
            edit.putLong(key, (Long) value);
        }

        boolean commit = edit.commit();
        return commit;
    }

    public static void putString(Context context, final String key, final String value) {
        if (context == null) {
            return;
        }
        final SharedPreferences settings = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        settings.edit().putString(key, value).apply();
    }
    public static String getString(Context context, String key) {
        if (context == null) {
            return "";
        }
        SharedPreferences sharedPreferences = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        return sharedPreferences.getString(key, "");
    }
    public static void putInt(Context context, final String key, final int value) {
        if (context == null) {
            return;
        }
        final SharedPreferences settings = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        settings.edit().putInt(key, value).apply();
    }
    public static int getInt(Context context, String key, int defaultValue) {
        if (context == null) {
            return defaultValue;
        }
        SharedPreferences sharedPreferences = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        return sharedPreferences.getInt(key, defaultValue);
    }
    public static void putLong(Context context, final String key, final Long value) {
        if (context == null) {
            return;
        }
        final SharedPreferences settings = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        settings.edit().putLong(key, value).apply();
    }
    public static long getLong(Context context, String key, Long defaultValue) {
        if (context == null) {
            return defaultValue;
        }
        SharedPreferences sharedPreferences = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        return sharedPreferences.getLong(key, defaultValue);
    }
    public static void putBoolean(Context context, final String key, final boolean value) {
        if (context == null) {
            return;
        }
        final SharedPreferences settings = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        settings.edit().putBoolean(key, value).apply();
    }
    public static boolean getBoolean(Context context, String key, boolean defaultValue) {
        if (context == null) {
            return defaultValue;
        }
        SharedPreferences sharedPreferences = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean(key, defaultValue);
    }

    public static void putFloat(Context context, final String key, final float value) {
        if (context == null) {
            return;
        }
        final SharedPreferences settings = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        settings.edit().putFloat(key, value).apply();
    }


    public static float getFloat(Context context, final String key, final float defaultValue) {
        if (context == null) {
            return defaultValue;
        }
        SharedPreferences sharedPreferences = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        return sharedPreferences.getFloat(key, defaultValue);
    }


    //销毁
    public static void remove(Context context, String key) {
        SharedPreferences preferences = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = preferences.edit();
        edit.remove(key);
        edit.commit();

    }
    /**
     * 是否登录
     *
     * @return
     */
    public boolean getIsLogin() {
        boolean isLogin = false;
        if (null != getLoadUserBean() && null != getLoadUserBean().getData()) {

            if (!TextUtils.isEmpty(getLoadUserBean().getData().getToken()) && getLoadUserBean().getData().getUserRank() != 99) {
                //已经登录
                isLogin = true;
            }

        }
//        HKLogUtils.e("=======是否登录========================"+isLogin);
        return isLogin;
    }

    //获取用户信息实体类
    public UserInfo getLoadUserBean() {
        Gson gson = new Gson();
        String json = sharedPreferences.getString(LOAD_USERINFO, null);
        Type type = new TypeToken<UserInfo>() {
        }.getType();
        if (gson.fromJson(json, type) == null) {
            return new UserInfo();
        }
        return gson.fromJson(json, type);
    }
    /**
     * 是否粉丝
     *
     * @return
     */
    public boolean getIsFans() {
        boolean isLogin = false;
        if (null != getLoadUserBean() && null != getLoadUserBean().getData()) {

            if (!TextUtils.isEmpty(getLoadUserBean().getData().getToken()) && getLoadUserBean().getData().getUserRank() != 99) {
                if (SpUtils.getInstance().getLoadUserBean().getData().getIsFans()==1){
                    return true;
                }
            }

        }
//        HKLogUtils.e("=======是否登录========================"+isLogin);
        return false;


    }

    //保存Dictionary实体类
    public void putLoadDictionaryBean(DictionaryData dictionaryData) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        Gson gson = new Gson();
        String json = gson.toJson(dictionaryData);
        editor.putString(LOAD_DICTIONARY, json);
        editor.apply();
    }

    //获取Dictionary实体类
    public DictionaryData getLoadDictionaryrBean() {
        Gson gson = new Gson();
        String json = sharedPreferences.getString(LOAD_DICTIONARY, null);
        Type type = new TypeToken<DictionaryData>() {
        }.getType();
        DictionaryData loadCreateAgencyBean = gson.fromJson(json, type);
        return loadCreateAgencyBean;
    }
    public String getUserICon() {
        if (getIsLogin()) {
            return getLoadUserBean().getData().getIcon();
        } else {
            return "";
        }
    }

}
